//
//  main.c
//  模拟实现strstr
//
//  Created by 卜绎皓 on 2022/3/26.
//

#include <stdio.h>
#include<assert.h>
 
char* my_strstr(const char* str1, const char* str2)
{
    assert(str1 && str2);
    const char* s1 = NULL;
    const char* s2 = NULL;
    const char* cp = str1;
    if (*str2 == '\0')
    {
        return (char*)str1;
    }
    while (*cp)
    {
        s1 = cp;
        s2 = str2;
        while (*s1 && *s2 && (*s1 == *s2))
        {
            s1++;
            s2++;
        }
        if (*s2 == '\0')
        {
            return cp;
        }
        cp++;
    }
    return NULL;
}

int main()
{
    char a[20] = "abbbcdef";
    char b[20] = "bcd";
    printf("%s\n", my_strstr(a, b));
    return 0;
}
